<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <title>学生管理系统</title>
    <style>
        body {
            background-color: #f3f4f6;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
        }

        .form-container {
            background-color: white;
            padding: 2rem;
            border-radius: 0.5rem;
            box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 28rem;
        }

        .form-title {
            font-size: 1.5rem;
            font-weight: bold;
            margin-bottom: 1.5rem;
            text-align: center;
        }

        .form-group {
            margin-bottom: 1rem;
        }

        .form-group:last-child {
            margin-bottom: 0;
        }

        label {
            display: block;
            color: #4b5563;
            font-weight: bold;
            margin-bottom: 0.5rem;
        }

        input[type="text"],
        input[type="password"] {
            border: 1px solid #d1d5db;
            padding: 0.5rem 0.75rem;
            width: 100%;
            border-radius: 0.25rem;
            outline: none;
            transition: border-color 0.3s ease;
        }

        input[type="text"]:focus,
        input[type="password"]:focus {
            border-color: #60a5fa;
        }

        .button-group {
            display: flex;
            gap: 1rem;
            margin-top: 1.5rem;
        }

        .custom-button {
            transition: background-color 0.3s ease, transform 0.3s ease;
            font-weight: bold;
            padding: 0.5rem 1rem;
            border-radius: 0.25rem;
            outline: none;
            width: 50%;
            cursor: pointer;
        }

        .custom-button:hover {
            transform: scale(1.05);
        }

        .blue-button {
            background-color: #3b82f6;
            color: white;
        }

        .blue-button:hover {
            background-color: #1d4ed8;
        }

        .green-button {
            background-color: #22c55e;
            color: white;
        }

        .green-button:hover {
            background-color: #15803d;
        }

        #message {
            margin-top: 1rem;
            text-align: center;
            color: red;
        }
    </style>
</head>

<body>
<div class="form-container">
    <h1 class="form-title">学生管理系统 - 登录</h1>
    <form id="loginForm" action="#">
        <div class="form-group">
            <label for="sysName">用户名:</label>
            <input type="text" id="sysName" name="sysName" placeholder="请输入用户名">
        </div>
        <div class="form-group">
            <label for="password">密码:</label>
            <input type="password" id="password" name="password" placeholder="请输入密码">
        </div>
        <div class="button-group">
            <input type="submit" id="loginSubmit" value="登录" class="custom-button blue-button">
            <input type="submit" id="registerBtn" value="注册" class="custom-button green-button">
        </div>
    </form>
    <div id="message"></div>
</div>
<script>
    $(document).ready(function () {
        // 注册按钮点击事件
        $("#registerBtn").click(function (e) {
            e.preventDefault();
            window.location.href = "zhuce.html";
        });

        // 登录按钮点击事件
        $("#loginSubmit").click(function (e) {
            e.preventDefault();
            // 获取表单数据
            var userName = $("#sysName").val();
            var password = $("#password").val().trim();

            // 简单前端验证
            if (!userName || !password) {
                $("#message").text("用户名和密码不能为空");
                return;
            }

            // 发送GET请求（注意：密码明文传输不安全，仅作演示）
            $.ajax({
                url: "/sysUser/login",
                type: "GET",
                data: {
                    userName: userName,
                    password: password
                },
                success: function (response) {
                    $("#message").text(response);
                    if (response === "success") {
                        // 显示“登录成功”提示
                        $("#message").text("登录成功，即将跳转...");
                        // 等待三秒后跳转首页，需替换为实际首页URL
                        setTimeout(function () {
                            window.location.href = "/home";
                        }, 3000);
                    }
                },
                error: function (xhr, status, error) {
                    // 处理错误响应，输出更详细的错误信息
                    $("#message").text("请求失败！错误信息: " + error + " 状态码: " + xhr.status);
                }
            });
        });

        // 回车键触发登录
        $(document).keypress(function (e) {
            if (e.which === 13) {
                $("#loginSubmit").click();
            }
        });
    });
</script>
</body>

</html>